
#include "stdafx.h"
#include "camera.h"

using namespace Blox;

Camera::Camera()
{
	SetupTransform( Vec(0.0f,0.0f,-5.0f), Vec(0.0f,0.0f,0.0f), Vec::Up );
	SetupProjection( 640.0f, 480.0f, 90.0f, 0.1f, 500.0f );
}

Camera::~Camera()
{
	
}

void Camera::SetupTransform( Blox::Vec const & rPos, Blox::Vec const & rLookAt, Blox::Vec const & rUp )
{
	// Initialize the view matrix
	D3DXVECTOR3 POS( rPos.x, rPos.y, rPos.z );
	D3DXVECTOR3 AT( rLookAt.x, rLookAt.y, rLookAt.z );
	D3DXVECTOR3 UP( rUp.x, rUp.y, rUp.z );

	D3DXMatrixLookAtLH( (D3DXMATRIX*)&m_mTransform, &POS, &AT, &UP );
}

void Camera::SetupProjection( float fViewWidth, float fViewHeight, float fFOVY_degrees, float fNear, float fFar )
{
	// Initialize the projection matrix
	D3DXMatrixPerspectiveFovLH( (D3DXMATRIX*)&m_mProjection, (FLOAT)D3DXToRadian(fFOVY_degrees), fViewWidth / fViewHeight, fNear, fFar );
}

void Camera::MoveRight( float const val )
{
	Vec const vMove( m_mTransform.GetX() * val );
	m_mTransform.SetTranslation( m_mTransform.GetTranslation() - vMove );
}

void Camera::MoveUp( float const val )
{
	Vec const vMove( m_mTransform.GetY() * val );
	m_mTransform.SetTranslation( m_mTransform.GetTranslation() - vMove );
}

void Camera::MoveForward( float const val )
{
	Vec const vMove( m_mTransform.GetZ() * val );
	m_mTransform.SetTranslation( m_mTransform.GetTranslation() - vMove );
}


